<template>
  <div class="home">
    <div class="header">
      <i class="iconfont icon-VIVO"></i>
    </div>
    <div class="official"></div>
    <div class="swiper">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item>
          <img
            src="https://shopstatic.vivo.com.cn/vivoshop/commodity/20180418/20180418104131830678_original.jpg"
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="https://shopstatic.vivo.com.cn/vivoshop/commodity/20220506/20220506200637180519_original.jpg"
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="https://shopstatic.vivo.com.cn/vivoshop/commodity/20220425/20220425203303640133_original.jpg"
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="https://shopstatic.vivo.com.cn/vivoshop/commodity/20220509/20220509161809929425_original.jpg"
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="https://shopstatic.vivo.com.cn/vivoshop/commodity/20220428/2022042822414954243_original.jpg"
          />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="icon">
      <ul class="icon-ul">
        <li class="icon-li" v-for="(item, index) in iconlist" :key="index">
          <router-link :to="{ path: item.to }">
            <img v-lazy="item.src" alt="" />
          </router-link>
        </li>
      </ul>
    </div>
    <div class="main">
      <div class="main-box" v-for="list in shoplist" :key="list.id">
        <h2>{{ list.title }}</h2>
        <ul>
          <li v-for="(v, i) in list.data" :key="i" @click="jumpDetail(list, v)">
            <div class="list">
              <div class="image">
                <img v-lazy="v.img_url" />
              </div>
              <p class="name">{{ v.name }}</p>
              <p class="nametwo">{{ v.content }}</p>
              <p class="price">￥{{ v.price }}.00</p>
            </div>
          </li>
        </ul>
      </div>
    </div>

    <v-footer></v-footer>
  </div>
</template>

<script>
import footer from "@/components/footer/index";
export default {
  components: {
    "v-footer": footer,
  },
  data() {
    return {
      iconlist: [
        {
          src: require("../../../static/img/xuangou.jpg"),
          to: "/goodss",
        },
        {
          src: require("../../../static/img/peijian.jpg"),
          to: "/parts",
        },
        {
          src: require("../../../static/img/pingbao.jpg"),
          to: "/",
        },
        {
          src: require("../../../static/img/dingzhi.jpg"),
          to: "/",
        },
      ],
      shoplist: [],
      total: 0,
      loading: false,
      finished: false,
    };
  },
  methods: {
    async getHomeData() {
      const res = await this.$http.getHomeData();
      this.shoplist = res.data;
      this.total = res.data.count;
    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(async () => {
        await this.getHomeData();
        // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (this.shoplist.length >= this.total) {
          this.finished = true;
        }
      }, 500);
    },
    jumpDetail(list, v) {
      this.$router.push({
        path: "/goodlist",
        query: {
          id: list.id,
          shop_id: v.id,
        },
      });
    },
  },
  created() {
    this.getHomeData();
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: auto;
  .header {
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1;
    height: 55px;
    line-height: 55px;
    font-size: 12px;
    background: black;
    i {
      font-size: 20px;
      color: white;
      text-align: center;
      display: block;
    }
  }
  .official {
    width: 100%;
    height: 30px;
    margin-top: 55px;
    background: url("../../../static/img/official.png") no-repeat;
    background-size: 100% 100%;
  }
  .swiper {
    margin-top: 1px;
    height: 265px;
    img {
      display: block;
      width: 100%;
      height: 265px;
    }
    .my-swipe .van-swipe-item {
      color: #fff;
      font-size: 20px;
      text-align: center;
      background-color: #39a9ed;
    }
  }
  .icon {
    width: 100%;
    height: 100px;
    background: white;
    border-bottom: 1px solid #f4f4f4;
    .icon-ul {
      width: 100%;
      height: 100px;
      .icon-li {
        width: 25%;
        height: 100%;
        float: left;
        margin: auto;
        a {
          width: 100%;
          height: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          img {
            display: block;
            width: 70%;
          }
        }
      }
    }
  }
  .main {
    margin-bottom: 60px;
    h2 {
      display: block;
      height: 30px;
      background: #f7f7f7;
      font-size: 18px;
      line-height: 30px;
      color: #333;
      text-align: center;
      font-weight: normal;
    }
    h2::before,
    h2::after {
      position: relative;
      margin: 0 5px;
      display: inline-block;
      content: " ";
      height: 1px;
      width: 19px;
      background-color: #9c9c9c;
      top: -6px;
    }
    ul {
      width: 100%;
      height: auto;
      overflow: hidden;
    }
    li {
      list-style: none;
      .list {
        width: 50%;
        box-sizing: border-box;
        height: auto;
        background: white;
        float: left;
        border-right: 1px solid #f4f4f4;
        border-top: 1px solid #f4f4f4;
        padding-bottom: 10px;
        .price {
          margin: auto;
          text-align: center;
          font-size: 14px;
          color: #f81200;
          font-weight: 500;
          padding-top: 10px;
          padding-bottom: 6px;
        }
        .name {
          width: 80%;
          height: 20px;
          line-height: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          margin: auto;
          font-size: 14px;
          font-weight: 600;
          text-align: center;
        }
        .nametwo {
          width: 90%;
          height: 30px;
          font-size: 12px;
          text-align: center;
          overflow: hidden;
          margin: auto;
          margin-top: 17px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .image {
          width: 100%;
          background: white;
          padding-top: 4px;
          padding-bottom: 10px;
          img {
            width: 95px;
            height: 100px;
            display: block;
            margin: auto;
            margin-top: 20px;
            margin-bottom: 10px;
          }
        }
      }
    }
  }
}
</style>
